package org.activequant.data.retrieval.dao;
import org.activequant.core.domainmodel.marketscanner.MarketScanSeries;
import org.activequant.core.domainmodel.marketscanner.MarketScanSeriesSpecification;
import org.activequant.dao.IMarketScanDao;
import org.activequant.data.retrieval.IMarketScanSeriesSource;
import org.apache.log4j.Logger;
/**
* MarketScan series source that fetches data from the database.<br/>
* An IMarketScanSeriesSource implementation. Holds the following associated variables:
* <ul>
* <li>dao(INewMarketScanDao)</li>
* </ul>
*  @author Dimitar Misev
*/
public class DaoMarketScanSeriesSource implements IMarketScanSeriesSource {
	private final Logger log = Logger.getLogger(getClass());
	/**
	 * private INewMarketScanDao dao;
	 */
	private IMarketScanDao dao;
	/**
	 * returns the associated dao(INewMarketScanDao)
	 * @return
	 */
	public IMarketScanDao getDao() {
		return dao;
	}
	/**
	 * sets the associated dao(ICandleDao) with the given val(INewMarketScanDao)
	 * @param val
	 */
	public void setDao(IMarketScanDao val) {
		dao = val;
	}
	/**
	 * returns a MarketScanSeries whose associated seriesSpecification(MarketScanSeriesSpecification) is set with the given specs(MarketScanSeriesSpecification).<br/>
	 * Sets its MarketScan elements by fetching the MarketScan(s) for the given specs(MarketScanSeriesSpecification) from the associated dao(INewMarketScanDao).
	 */
	public MarketScanSeries fetch(MarketScanSeriesSpecification specs) throws Exception {
		if(dao == null) {
			throw new IllegalStateException("dao property not set");
		}
		MarketScanSeries series = new MarketScanSeries(specs);
		log.debug("populating series from the data source: " + specs);
		series.setMarketScans(dao.findByMarketScanSeriesSpecification(specs));
		return series;
	}
	/**
	 * returns the simple name of this class
	 * @return
	 */
	public String getVendorName() {
		return getClass().getSimpleName();
	}
}
